------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:/Users/silvio/Documents/CVR/ryp/output/s3_simulation.log
  log type:  text
 opened on:   4 Jul 2018, 12:28:25

. 
. matrix drop _all

. set more off

. 
. set matsize 1392

. scalar nstrata=58                      /*=58, CVR strata*/

. 
. set seed 98034

. 
. use "${data}/${datafile}" , replace

. 
. mkmat y

. scalar perpeh=1

. 
. **************************************************************
. 
. scalar nsimu=1000

. matrix one7=J(1,7,1)

. matrix res=J(9, 16, 0)

. ******************************
. 
. scalar icounter=1

. foreach ii in 32 36 25 35 51 14 11 47 48 {  /* begin loop strata */
  2. scalar jhat=`ii'
  3. di jhat
  4. 
. matrix xe=J(nsimu, 9, 0)
  5. matrix oxed=J(nsimu,1,0)
  6. matrix oxeb=J(nsimu,1,0)
  7. 
. matrix xed=J(nsimu,1,0)
  8. matrix xeb=J(nsimu,1,0)
  9. 
. 
. scalar perpeh=1
 10. scalar jj1=(jhat-1)*8*3+(perpeh-1)*8+1
 11. scalar jj2=jj1+6
 12. matrix a=y[jj1..jj2,1]              /*original data*/
 13. run "$code/analya"
 14. matrix m_mate=mijk[1..8,modeli]           /*estimated parameters*/
 15. scalar modelixe=modeli
 16. 
. 
. 
. scalar perpeh=2
 17. scalar jj1=(jhat-1)*8*3+(perpeh-1)*8+1
 18. scalar jj2=jj1+6
 19. matrix a=y[jj1..jj2,1]              /*original data*/
 20. run "$code/analya"
 21. matrix m_mats=mijk[1..8,modeli]           /*estimated parameters. True values for simulation*/
 22. scalar ms=int(nmv[modeli, 1]+0.5)                               /*nctotal*/
 23. scalar modelixs=modeli
 24. 
. 
. forval inumi = 1/1000{              /*inumi=number of simulations*/
 25. 
. * E
. forval i = 1/7{
 26. scalar m=m_mate[`i',1]
 27. matrix a[`i',1]=rpoisson(m)
 28. }
 29. matrix ae=a
 30. scalar m=m_mate[8,1]
 31. matrix xe[`inumi',1]=rpoisson(m)+one7*ae    /*1. Simulated for E */
 32. 
. *Estimate on simulated data
. run "$code/analya"
 33. ****************
. if modeli>0{
 34. matrix xe[`inumi',2]=int(nmv[modeli, 1]+0.5)                            /*nctotal*/
 35. matrix xe[`inumi',3]=nmv[modeli, 2]                                  /*vnctotal*/
 36. *matrix bm000[jhat,2]=smodel[jhat,1]-bm000[jhat,1]  /*scalar vm000=vnctotal-m000*/
. } /*modeli*/
 37. ****************
. * S
. forval i = 1/7{
 38. scalar m=m_mats[`i',1]
 39. matrix a[`i',1]=rpoisson(m)
 40. }
 41. matrix as=a
 42. scalar m=m_mats[8,1]
 43. matrix xe[`inumi',4]=rpoisson(m)+one7*as  /*3. Simulated for S */
 44. 
. *Estimate on simulated data
. run "$code/analya"
 45. ****************
. * Direct estimation for the Shining Path
. if modeli>0{
 46. matrix xe[`inumi',5]=int(nmv[modeli, 1]+0.5)                            /*nctotal Direct Estimation*/
 47. matrix xe[`inumi',6]=nmv[modeli, 2]                                  /*vnctotal Direct Estimation*/
 48. matrix oxed[`inumi',1]=1
 49. matrix xed[`inumi',1]=xe[`inumi',5]-xe[`inumi',4]
 50. 
. 
. 
. } /*modeli*/
 51. ****************
. * TRC estimation for the Shining Path
. *E+S a
. matrix a=ae+as                   /*5. Simulated data of sum of E+S */
 52. *Estimate on simulated data
. run "$code/analya"
 53. ****************
. if modeli>0{
 54. matrix xe[`inumi',7]=int(nmv[modeli, 1]+0.5)- xe[`inumi',2]      /*nctotal TRC*/
 55. matrix xe[`inumi',8]=nmv[modeli, 2]+ xe[`inumi',3]          /*vnctotal TRC*/
 56. 
. if xe[`inumi',7]-xe[`inumi',4]>0{
 57. matrix oxeb[`inumi',1]=1
 58. matrix xeb[`inumi',1]=xe[`inumi',7]-xe[`inumi',4]
 59. matrix xe[`inumi',9]=xe[`inumi',7]-xe[`inumi',4]
 60. }
 61. 
. } /*modeli*/
 62. ****************
. 
. 
. 
. 
. } /*simulation*/
 63. 
. 
. *matrix list xe
. 
. matrix rmsed=xed'*xed
 64. matrix rmseb=xeb'*xeb
 65. matrix nrmsed=oxed'*oxed
 66. matrix nrmseb=oxeb'*oxeb
 67. scalar rmseds=sqrt(rmsed[1,1]/nrmsed[1,1])
 68. scalar rmsebs=sqrt(rmseb[1,1]/nrmseb[1,1])
 69. 
. 
. matrix vedm=xe[1...,6]
 70. matrix vebm=xe[1...,8]
 71. matrix vedmx=oxed'*vedm/nrmsed[1,1]
 72. matrix vebmx=oxeb'*vebm/nrmseb[1,1]
 73. scalar ved=sqrt(vedmx[1,1])
 74. scalar veb=sqrt(vebmx[1,1])
 75. 
. 
. 
. clear
 76. svmat xe, names(reg)
 77. *summ
. summ reg4 if reg4>0,d
 78. scalar msample=r(mean)  
 79. scalar ssample=r(sd)  
 80. 
. summ reg5 if reg5>0,d
 81. scalar mdir=r(mean)  
 82. scalar sdir=r(sd)  
 83. 
. sum reg7 if reg8>0,d
 84. scalar mbasm=r(mean)  
 85. scalar sbasm=r(sd)  
 86. 
.                   
. matrix res[icounter,1]=jhat
 87. matrix res[icounter,2]=ms
 88. matrix res[icounter,3]=msample
 89. matrix res[icounter,4]=ssample
 90. 
. matrix res[icounter,5]=mdir
 91. matrix res[icounter,6]=mdir-msample
 92. 
. matrix res[icounter,7]=ved
 93. matrix res[icounter,8]=sdir
 94. matrix res[icounter,9]=rmseds
 95. matrix res[icounter,10]=nrmsed[1,1]
 96. matrix res[icounter,11]=mbasm
 97. matrix res[icounter,12]=mbasm-msample
 98. matrix res[icounter,13]=veb
 99. matrix res[icounter,14]=sbasm
100. matrix res[icounter,15]=rmsebs
101. matrix res[icounter,16]=nrmseb[1,1]
102. 
. scalar icounter=icounter+1                        
103. } /* end loop strata*/
32
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%        685.5            656
 5%          707            661
10%        714.5            664       Obs                1000
25%          730            670       Sum of Wgt.        1000

50%          749                      Mean            749.655
                        Largest       Std. Dev.      27.69348
75%          768            827
90%          785            831       Variance       766.9289
95%          796            835       Skewness       .0770947
99%        815.5            835       Kurtosis       3.061323

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          190            161
 5%          216            171
10%          233            179       Obs                 998
25%          269            180       Sum of Wgt.         998

50%          331                      Mean            443.503
                        Largest       Std. Dev.      332.2378
75%          449           2153
90%          770           2169       Variance       110381.9
95%         1283           2246       Skewness       2.966889
99%         1819           2809       Kurtosis       12.95586

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%           16           -278
 5%          117           -235
10%        161.5           -135       Obs                1000
25%          289           -103       Sum of Wgt.        1000

50%          446                      Mean            434.442
                        Largest       Std. Dev.      204.6476
75%          560           1025
90%        686.5           1096       Variance       41880.65
95%        768.5           1117       Skewness       .1700183
99%        972.5           1261       Kurtosis       3.317071
36
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%        577.5            557
 5%          594            565
10%          605            565       Obs                1000
25%          621            567       Sum of Wgt.        1000

50%          637                      Mean            636.786
                        Largest       Std. Dev.      24.47761
75%          653            697
90%          667            698       Variance       599.1534
95%          678            699       Skewness      -.1365931
99%        691.5            702       Kurtosis        2.99315

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          461            414
 5%          488            444
10%          511            445       Obs                 798
25%          556            455       Sum of Wgt.         798

50%          651                      Mean           732.2118
                        Largest       Std. Dev.      261.3096
75%          840           2055
90%         1037           2110       Variance       68282.71
95%         1235           2208       Skewness       2.373067
99%         1827           2491       Kurtosis       11.26716

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%        159.5           -305
 5%          425           -189
10%          671           -115       Obs                1000
25%        875.5            -42       Sum of Wgt.        1000

50%       1039.5                      Mean           1061.737
                        Largest       Std. Dev.      385.6222
75%       1221.5           2766
90%       1497.5           2878       Variance       148704.5
95%         1656           2969       Skewness       1.358953
99%         2205           4773       Kurtosis       13.49307
25
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%          884            853
 5%          904            858
10%          917            859       Obs                1000
25%          937            867       Sum of Wgt.        1000

50%          957                      Mean            957.329
                        Largest       Std. Dev.      31.42433
75%          978           1039
90%          997           1049       Variance       987.4882
95%         1009           1051       Skewness      -.1033181
99%         1031           1053       Kurtosis       3.111604

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          722            480
 5%          808            597
10%          829            618       Obs                 608
25%          877            632       Sum of Wgt.         608

50%          944                      Mean           959.2023
                        Largest       Std. Dev.      118.8617
75%         1024           1335
90%         1108           1347       Variance       14128.09
95%         1182           1369       Skewness       .5485343
99%         1302           1391       Kurtosis       4.117636

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%         78.5            -18
 5%        196.5             23
10%          420             33       Obs                1000
25%          776             40       Sum of Wgt.        1000

50%          851                      Mean            797.721
                        Largest       Std. Dev.      228.9502
75%          921           1161
90%        983.5           1186       Variance       52418.21
95%       1018.5           1369       Skewness      -1.825351
99%         1107           1435       Kurtosis        5.94407
35
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%          256            241
 5%        265.5            247
10%          273            251       Obs                1000
25%          283            252       Sum of Wgt.        1000

50%          295                      Mean             294.83
                        Largest       Std. Dev.      17.20765
75%        306.5            340
90%          317            343       Variance       296.1032
95%          324            359       Skewness        .012277
99%        332.5            360       Kurtosis       3.056737

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          251            236
 5%          266            247
10%          275            248       Obs                 566
25%          291            248       Sum of Wgt.         566

50%          314                      Mean           339.3339
                        Largest       Std. Dev.      82.44633
75%          362            748
90%          427            790       Variance       6797.398
95%          489            946       Skewness       3.140874
99%          688            983       Kurtosis       18.47139

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%        250.5            165
 5%          300            192
10%          329            229       Obs                1000
25%          367            233       Sum of Wgt.        1000

50%          407                      Mean            410.142
                        Largest       Std. Dev.      70.30177
75%        445.5            681
90%        493.5            686       Variance       4942.338
95%        540.5            698       Skewness       .5220228
99%          610            719       Kurtosis         4.5668
51
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%        374.5            347
 5%          394            356
10%          401            366       Obs                1000
25%          412            369       Sum of Wgt.        1000

50%          426                      Mean            426.117
                        Largest       Std. Dev.      20.69705
75%        439.5            479
90%        453.5            481       Variance       428.3677
95%          461            484       Skewness      -.0196424
99%          473            486       Kurtosis       3.034072

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          340            296
 5%          361            317
10%          375            326       Obs                 562
25%          399            337       Sum of Wgt.         562

50%        445.5                      Mean           493.6192
                        Largest       Std. Dev.        160.96
75%          513           1248
90%          663           1286       Variance       25908.13
95%          834           1344       Skewness       2.706694
99%         1227           1570       Kurtosis       12.37817

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%        224.5            158
 5%        287.5            160
10%        306.5            170       Obs                1000
25%        694.5            199       Sum of Wgt.        1000

50%        973.5                      Mean             990.51
                        Largest       Std. Dev.       522.187
75%       1221.5           3651
90%       1505.5           4274       Variance       272679.3
95%         1831           4606       Skewness        1.82339
99%       2673.5           5262       Kurtosis       12.43024
14
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%         1534           1503
 5%         1563           1515
10%         1575           1515       Obs                1000
25%         1600           1515       Sum of Wgt.        1000

50%         1628                      Mean           1628.797
                        Largest       Std. Dev.      41.39995
75%         1656           1731
90%       1683.5           1732       Variance       1713.956
95%         1701           1733       Skewness       .0526381
99%       1723.5           1777       Kurtosis       2.879476

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%         1291           1214
 5%       1350.5           1232
10%         1388           1262       Obs                 980
25%       1463.5           1274       Sum of Wgt.         980

50%         1594                      Mean           1658.809
                        Largest       Std. Dev.      287.6962
75%         1773           3150
90%       1997.5           3188       Variance       82769.12
95%         2185           3713       Skewness       2.214407
99%         2736           3735       Kurtosis       11.70614

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%       1295.5            909
 5%       1782.5           1043
10%         2217           1086       Obs                1000
25%       2440.5           1127       Sum of Wgt.        1000

50%       2975.5                      Mean           3438.377
                        Largest       Std. Dev.       1180.62
75%         4400           6376
90%       4887.5           6487       Variance        1393863
95%       5278.5           6489       Skewness       .2226186
99%         6062           6616       Kurtosis       1.935766
11
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%          628            608
 5%          648            618
10%          658            619       Obs                1000
25%          674            620       Sum of Wgt.        1000

50%          691                      Mean            691.662
                        Largest       Std. Dev.      26.42503
75%          710            760
90%          726            761       Variance        698.282
95%          736            761       Skewness      -.0090376
99%        754.5            762       Kurtosis       2.931839

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          569            524
 5%          601            532
10%          619            547       Obs                 993
25%          660            550       Sum of Wgt.         993

50%          716                      Mean           742.0383
                        Largest       Std. Dev.      128.4897
75%          790           1413
90%          892           1425       Variance       16509.62
95%          983           1713       Skewness       2.372989
99%         1209           1850       Kurtosis       14.48035

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%        445.5            177
 5%          631            192
10%          963            196       Obs                1000
25%       1208.5            320       Sum of Wgt.        1000

50%         1780                      Mean           1863.434
                        Largest       Std. Dev.      827.4513
75%         2494           4181
90%       2951.5           4235       Variance       684675.7
95%       3252.5           4539       Skewness       .3735155
99%       3834.5           4718       Kurtosis       2.394795
47
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%          424            411
 5%          439            411
10%          448            414       Obs                1000
25%          460            415       Sum of Wgt.        1000

50%          475                      Mean            475.218
                        Largest       Std. Dev.      22.04542
75%          490            531
90%          504            532       Variance       486.0005
95%          511            538       Skewness      -.0062341
99%        527.5            554       Kurtosis       2.950258

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          306            246
 5%          352            275
10%          375            278       Obs                 953
25%          415            291       Sum of Wgt.         953

50%          474                      Mean            494.043
                        Largest       Std. Dev.      117.3859
75%          544           1032
90%          637           1034       Variance       13779.44
95%          711           1166       Skewness       1.768685
99%          929           1366       Kurtosis       9.437814

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%        191.5             41
 5%          230            138
10%          245            144       Obs                1000
25%        291.5            162       Sum of Wgt.        1000

50%          506                      Mean            509.212
                        Largest       Std. Dev.       267.617
75%        606.5           2013
90%          716           2333       Variance       71618.84
95%          839           3130       Skewness       3.622965
99%         1595           3265       Kurtosis       29.40595
48
number of observations will be reset to 1000
Press any key to continue, or Break to abort
obs was 0, now 1000

                            reg4
-------------------------------------------------------------
      Percentiles      Smallest
 1%        379.5            361
 5%          393            364
10%          401            367       Obs                1000
25%          413            371       Sum of Wgt.        1000

50%          426                      Mean            426.104
                        Largest       Std. Dev.      20.07666
75%          439            481
90%          452            481       Variance       403.0723
95%          460            485       Skewness       .0439759
99%          474            492       Kurtosis       3.065869

                            reg5
-------------------------------------------------------------
      Percentiles      Smallest
 1%          349            341
 5%          369            344
10%          385            347       Obs                 537
25%          412            347       Sum of Wgt.         537

50%          464                      Mean           527.6536
                        Largest       Std. Dev.      196.9374
75%          572           1463
90%          675           1545       Variance       38784.34
95%          952           1600       Skewness       2.690027
99%         1334           1665       Kurtosis       11.69822

                            reg7
-------------------------------------------------------------
      Percentiles      Smallest
 1%        300.5            198
 5%        383.5            222
10%          437            223       Obs                1000
25%        525.5            233       Sum of Wgt.        1000

50%          604                      Mean            646.962
                        Largest       Std. Dev.      222.1638
75%          730           1612
90%        893.5           2296       Variance       49356.74
95%         1000           2392       Skewness       3.200723
99%       1362.5           3221       Kurtosis       28.22199

. matrix list res

res[9,16]
            c1          c2          c3          c4          c5          c6          c7          c8          c9         c10
r1          32         751     749.655   27.693481   443.50301  -306.15199   410.08905   332.23776   450.12189         998
r2          36         637     636.786   24.477609   732.21178   95.425779   410.37785   261.30961    277.7397         798
r3          25         958     957.329   31.424326    959.2023   1.8733026   288.79618   118.86165   115.91354         608
r4          35         294      294.83    17.20765   339.33392   44.503922   130.00757   82.446334   92.314325         566
r5          51         427     426.117   20.697045   493.61922   67.502217    261.2037   160.96003   172.62295         562
r6          14        1628    1628.797   41.399949   1658.8092   30.012184   326.71828   287.69624   288.16486         980
r7          11         692     691.662   26.425027   742.03827   50.376268   141.83192   128.48975   136.51046         993
r8          47         475     475.218   22.045418   494.04302   18.825022   165.31537   117.38585   115.92214         953
r9          48         426     426.104   20.076659   527.65363   101.54963   327.93151    196.9374   220.95148         537

           c11         c12         c13         c14         c15         c16
r1     434.442    -315.213   270.49379   204.64761   164.93844          58
r2    1061.737     424.951   426.24745   385.62216   588.89732         920
r3     797.721    -159.608   112.49112   228.95023    85.81576         148
r4     410.142     115.312   75.132279   70.301765   136.23435         955
r5      990.51     564.393   498.28617   522.18701   836.68147         838
r6    3438.377     1809.58   465.05731     1180.62    2200.788         962
r7    1863.434    1171.772   429.03431   827.45133   1478.3408         939
r8     509.212      33.994   350.44545   267.61697   312.71148         591
r9     646.962     220.858   250.51143   222.16378   325.41649         912

. clear

. svmat res, names(v)
number of observations will be reset to 9
Press any key to continue, or Break to abort
obs was 0, now 9

. ren v1 Stratum          

. ren v3 N 

. format %7.2f N

. 
. ren v5 Estimated 

. ren v6 Biasd    

. ren v7 Est_SEd  

. ren v8 Sample_SEd       

. ren v9 RMSEd    

. ren v10 Valid_Obsd

. 
. ren v11 Estimateb

. ren v12 Biasb   

. ren v13 Est_SEb

. ren v14 Sample_SEb      

. ren v15 RMSEb   

. ren v16 Valid_Obsb

. 
. la var Estimated "Estimate" 

. la var Biasd "Bias"     

. la var Est_SEd "Estimated S.E." 

. la var Sample_SEd "Sample S.D." 

. la var RMSEd "Sample RMSE"      

. la var Valid_Obsd "Valid Observations"

. 
. export excel Stratum N Estimated Biasd Est_SEd Sample_SEd RMSEd Valid_Obsd Estimateb Biasb Est_SEb Sample_SEb RMSEb Valid_Ob
> sb ///
> using "$excel/${name}.xls", sheet("res") sheetmodify firstrow(varlabels) missing(".")
file C:/Users/silvio/Documents/CVR/ryp/excel/s3_simulation.xls saved

. 
. capture log close
